package com.ruoyi.web.controller.system;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.GjjSeachLog;
import com.ruoyi.system.service.impl.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/system/visit")
public class SysVisitController extends BaseController {
    @Autowired
    private VisitService visitService;


    @PreAuthorize("@ss.hasPermi('system:visit:index')")
    @GetMapping("/list")
    public Object list() {
        return  visitService.list();
    }

    @PreAuthorize("@ss.hasPermi('system:visit:index')")
    @GetMapping("/queryList")
    public Object queryList(String name, String startDate, String endDate) {
        startPage();
        List<GjjSeachLog> gjjSeachLogs = visitService.queryList(name, startDate, endDate);
        return  getDataTable(gjjSeachLogs);
    }


    @Log(title = "访问管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:visit:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response,  GjjSeachLog gjjSeachLog) {
        String name = gjjSeachLog.getName();
        String startDate = gjjSeachLog.getStartDate();
        String endDate = gjjSeachLog.getEndDate();
        List<GjjSeachLog> gjjSeachLogs = visitService.queryList(name,startDate,endDate);
        ExcelUtil<GjjSeachLog> util = new ExcelUtil<GjjSeachLog>(GjjSeachLog.class);
        util.exportExcel(response, gjjSeachLogs, "访问数据");
    }

}
